function sseTool(url, config) {
  const source = new EventSource(url, { withCredentials: true });
  if (Object.prototype.toString.call(config) === '[object Object]') {
    const eventName = Object.keys(config);
    eventName.forEach(key => {
      const configItem = config[key];
      if (typeof configItem === 'function') source.addEventListener(key, configItem, false);
    });
  }
  return source;
}

export default sseTool;
